(function(Jml, EFactory) {
	/**
	 * 注册扩展类型的基类
	 */
	EFactory.add("ext", {
		init:function(op){
			$.extend(this,op);
		},
		/** 
		 * 扩展属性模板编译方法
		 * @param {jqDom} target : 作用对象
		 *  @param {object} config : 配置信息
		 *  @param {object} view : 视图对象
		 */
		compile : function() {
			if (this.controlName) {
				var ctr = this.target[this.controlName];
				ctr && ctr.call(this.target, this.value);
			}
		}
	});
	/**
	 * 注册tip类型控件
	 */
	EFactory.addExt("tip", {
		controlName : "tip"
	});
	
	/**
	 * 注册button类型控件
	 */
	EFactory.addControl("button",{
		template : function(){
			var config = this.config.execute(),
				op = config.option;
			//如果click对应function，则通过on绑定实现
			if(op.click && typeof op.click == "function"){
				config.event.click = op.click;
				op.click = null;
			}

			//加入占位符
			//op.jmlHtmlProp = " ${prop} ";
			op.attr = config.prop;
			return Ccay.UI.button(op);
		}
	});
	
	/**
	 * 注册menuButton类型控件
	 */
	EFactory.addControl("menuButton",{
		controlName : "ccayMenuButton",
		template : "<div ${prop} />",
		_buildConfig:function(){
			//将children保存到option的menus属性中
			var children = this.domTemplate.children(), content = [];
			if(children.length){
				var childConfig = new Ccay.Jml.ConfigLoader(null,this.page);
				children.each(function(){
					childConfig.load($(this));
					content.push ('{'+childConfig.option + '}');
				});
			}
			this.config.option += (this.config.option ?  "," : "") +
			"menus:[" +  content.join(",\n") + "]";
			
			//再调用一下父的_buildConfig方法
			this.callParent("_buildConfig");
		}
	});
	
})(Ccay.Jml, Ccay.Jml.ElementFactory);